# """Copyright(c) 2024 hzy. All Rights Reserved.
# """
#
#
# import torch.nn as nn
# from ...core import register
#
# __all__ = ['MYRTDETR', ]
#
#
# class AuxiliaryBranch(nn.Module):
#     def __init__(self, input_dim, output_dim):
#         super(AuxiliaryBranch, self).__init__()
#         # 定义辅助分支网络的结构
#         self.aux_net = nn.Sequential(
#             nn.Linear(input_dim, 128),
#             nn.ReLU(),
#             nn.Linear(128, output_dim)
#         )
#
#     def forward(self, video_features):
#         # 处理视频特征
#         aux_out = self.aux_net(video_features)
#         return aux_out
#
#
# @register()
# class MYRTDETR(nn.Module):
#     __inject__ = ['backbone', 'encoder', 'decoder', ]
#
#     def __init__(self, \
#                  backbone: nn.Module,
#                  encoder: nn.Module,
#                  decoder: nn.Module,
#                  aux_branch: AuxiliaryBranch = None,  # 增加辅助分支
#                  use_aux: bool = True,  # 是否使用辅助分支
#                  ):
#         super().__init__()
#         self.backbone = backbone
#         self.encoder = encoder
#         self.decoder = decoder
#         self.aux_branch = aux_branch
#         self.use_aux = use_aux
#
#     def forward(self, x, targets=None, video_features=None):
#         # 主干网络处理
#         x = self.backbone(x)
#         # 如果使用辅助分支并且提供了视频特征
#         if self.use_aux and self.aux_branch is not None and video_features is not None:
#             aux_out = self.aux_branch(video_features)
#             # 合并辅助分支输出与主网络输出，可以采用加权求和或拼接
#             # 这里选择简单的加法
#             x = x + aux_out
#
#         x = self.encoder(x)
#         # 解码器处理
#         x = self.decoder(x, targets)
#         return x
#
#     def deploy(self):
#         # 部署模型时禁用辅助分支
#         self.use_aux = False
#         self.eval()
#         for m in self.modules():
#             if hasattr(m, 'convert_to_deploy'):
#                 m.convert_to_deploy()
#         return self
